/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aviso.facade;

import aviso.entity.AdvertQuery;
import aviso.entity.Bounds;
import aviso.entity.UserName;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

/**
 *
 * @author avgusti
 */
@Stateless
public class AdvertQueryFacade extends AbstractFacade<AdvertQuery> {

    @PersistenceContext(unitName = "aviso")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public AdvertQueryFacade() {
        super(AdvertQuery.class);
    }

//    public List<AdvertQuery> listInBoundsByUser(Bounds bounds, UserName userName)
//    {
//        return  em.createNamedQuery("AdvertQuery.lookUpInBoundsByUser",AdvertQuery.class)
//                .setParameter("lats", bounds.getSlat())
//                .setParameter("latn", bounds.getNlat())
//                .setParameter("lngw", bounds.getWlng())
//                .setParameter("lnge", bounds.getElng())
//                .setParameter("userid", userName.getId()).getResultList();
//    }
    public List<AdvertQuery> listByUser(UserName userName) {
        List<AdvertQuery> list = em.createNamedQuery("AdvertQuery.lookUpByUser", AdvertQuery.class).setParameter("userid", userName.getId()).getResultList();
        int i = 0;
        for (AdvertQuery a : list) {
            i++;
            a.setNumber(i);
        }
        return list;
    }
}
